<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }

    body,
    html {
      width: 100vw;
      height: 100vh;
    }

    .dv1 {
      width: 300px;
      height: 300px;
      background-color: hotpink;
      display: flex;
      justify-content: center;
      align-items: center;
      position: absolute;
      top: 100px;
      left: 50%;
      transform: translateX(-50%);
    }

    .dv2 {
      width: 200px;
      height: 200px;
      background-color: green;
    }
  </style>
</head>

<body>
  <!-- 
    阻止默认事件，让链接不跳转，或让表单不提交
      e.preventDefault();
    阻止默认事件的冒泡
      e.stopPropagation();
    
    return false;
      可以阻止冒泡事件
  -->
  <!-- <a href="https://baidu.com">百度</a> -->
  <div class="dv1">
    <div class="dv2">son</div>
  </div>
</body>
<script>
  let a = document.querySelector("a");
  a.addEventListener("click", (e) => {
    e.preventDefault(); //标准的写法
    // return false; 也可以阻止跳转，后面的代码不再执行了
  });
</script>
<script>
  let dv1 = document.querySelector(".dv1");
  let dv2 = document.querySelector(".dv2");
  dv1.addEventListener("click", () => {
    alert(`我是div1`);
  });
  /* dv2.addEventListener("click", (e) => {
    alert(`我是div2`);
    // e.stopPropagation();
  }); */
</script>

</html>